package com.agadmin.api;

import com.agadmin.manage.apiEnum.menuApi.MenuEnumApi;
import com.agadmin.manage.apiEnum.softwareApi.SoftwareEnumApi;
import java.util.Objects;

public enum ServiceEnumApi {
    Menu(MenuEnumApi.class,"Menu",1),//desc和枚举名要相等
    SOFTWARE(SoftwareEnumApi.class,"SOFTWARE",2),//desc和枚举名要相等
    ;

    Class name;

    String desc;

    Integer code;

    private ServiceEnumApi(Class name, String desc,Integer code) {
        this.name = name;
        this.desc = desc;
        this.code=code;
    }


    // 通过code获取名称
    public static Class getNameByCode(int code) {
        for (ServiceEnumApi c : ServiceEnumApi.values()) {
            if (c.getCode() == code) {
                return c.name;
            }
        }
        return null;
    }

    // 通过desc获取名称
    public static Class getNameByDesc(String desc) {
        for (ServiceEnumApi c : ServiceEnumApi.values()) {
            if (Objects.equals(c.getDesc(), desc)) {
                return c.name;
            }
        }
        return null;
    }
    // 通过名称获取code
    public static Integer getCodeByName(Class name) {
        for (ServiceEnumApi c : ServiceEnumApi.values()) {
            if (Objects.equals(c.getName(), name)) {
                return c.code;
            }
        }
        return null;
    }

    public Class getName() {
        return name;
    }

    public void setName(Class name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
